package com.xyb.utils;

import java.util.regex.Pattern;

public class RegUtils {
    private static final String IPHONE_PATTERN = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
    private static final String EMAIL_PATTERN = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$";

    /**
     * 判断是否是手机号
     * @param iphoneNo
     * @return true 是手机号
     */
    public static boolean isPhoneNo(String iphoneNo){
        boolean b = Pattern.matches(IPHONE_PATTERN, iphoneNo);
        return b;
    }

    /**
     * 判断是否是邮箱
     * @param email
     * @return true 是邮箱
     */
    public static boolean isEmail(String email){
        boolean b = Pattern.matches(EMAIL_PATTERN, email);
        return b;
    }

    public static void main(String[] args) {
        boolean phoneNo = isPhoneNo("1525192266");
        System.out.println("phoneNo = " + phoneNo);

        boolean email = isEmail("939949243@qq.com");
        System.out.println("email = " + email);
    }
}
